<template>
	<view class="pt-5">
		<view class="flex align-center bg-white" style="height: 44rpx;">
			<!-- 搜索框 -->
			<view class="ml-2 flex align-center flex-1 rounded-circle px-1"
				style="height: 40px; background-color:#F6F7F8; color: #959FA0;">
				<uni-icons type="search" color="#ccc" size="20" class="px-2"></uni-icons>
				<input v-model="InputValue" type="text" placeholder-class="font" placeholder="请输入内容">
			</view>
			<view class="flex align-center px-2 font" @click="GoGoods()">搜索</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				setvalue:[],
				InputValue: '',
			}
		},
		onLoad() {},
		methods: {
			GoGoods() {
				var that = this;
				if (this.InputValue == '') {
					uni.showToast({
						title: '请输入您要查询的关键字',
						icon: 'none'
					})
					return
				} else {
					var value = uni.getStorageSync('searchValue') // 每次点击搜索先获取存储本地的历史记录
					var flag = true;
					console.log(value);
					if (value.length>0) {
						value.forEach(item => {
							if (item == this.InputValue) {
								flag = false;
							}
						})
						if (flag) {
							value.unshift(this.InputValue);
							uni.setStorageSync('searchValue', value);
							uni.navigateTo({
								url: "/pages/index/manygoods?value=" + this.InputValue
							})
						} else {
							uni.navigateTo({
								url: "/pages/index/manygoods?value=" + this.InputValue
							})
						}
					} else {
						that.setvalue.unshift(this.InputValue);
						uni.setStorageSync('searchValue',that.setvalue);
						uni.navigateTo({
							url: "/pages/index/manygoods?value=" + this.InputValue
						})
					}



				}
			},

		},
	}
</script>

<style>
</style>